package com.atguigu.lease.web.admin.controller.apartment;


import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.PaymentType;
import com.atguigu.lease.web.admin.service.PaymentTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "支付方式管理")
@RequestMapping("/admin/payment")
@RestController
public class PaymentTypeController {

    @Autowired
    private PaymentTypeService paymentTypeService;//注入 PaymentTypeService

    @Operation(summary = "查询全部支付方式列表")
    @GetMapping("list")
    public Result<List<PaymentType>> listPaymentType() {
        //调用mybatis-plus的查询方式
        List<PaymentType> list = paymentTypeService.list();
        //集合装到result.ok(T)
        Result<List<PaymentType>> result = Result.ok(list);
        //集合装到返回值中
        return result;
    }

    @Operation(summary = "保存或更新支付方式")
    @PostMapping("saveOrUpdate")
    public Result saveOrUpdate(@RequestBody PaymentType paymentType) {
        //1.调用saveOrUpdate
        boolean is = paymentTypeService.saveOrUpdate(paymentType);
        //2.判定结果处理
        if (!is){
            return Result.fail();
        }
        return Result.ok();
    }

    @Operation(summary = "根据ID删除支付方式")
    @DeleteMapping("deleteById")
    public Result deletePaymentById(@RequestParam Long id) {

        paymentTypeService.removeById(id);

        return Result.ok();
    }

}















